package s47.dqj.dao;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import s47.dqj.bean.PatientInfo;

/**
 * 1.患者表
 * @author Administrator
 *
 */ 
@Repository("patientInfoDaoImpl")
public class PatientInfoDaoImpl extends HibernateDaoSupport implements PatientInfoDaoInf{
	
	/* (non-Javadoc)
	 * @see s47.dqj.dao.PatientInfoDaoInf#setSupperSessionFactory(org.hibernate.SessionFactory)
	 */
	@Override
	@Resource(name="sessionFactory")
	public void setSupperSessionFactory(SessionFactory sessionFactory){
		super.setSessionFactory(sessionFactory);
	}
	
	/* (non-Javadoc)
	 * @see s47.dqj.dao.PatientInfoDaoInf#findAll()
	 */
	@Override
	public List<PatientInfo> findAll(){
		String hql="from PatientInfo";
		return getHibernateTemplate().find(hql);
	}
	
	/* (non-Javadoc)
	 * @see s47.dqj.dao.PatientInfoDaoInf#findObject(s47.dqj.bean.PatientInfo)
	 */
	@Override
	public PatientInfo findObject(PatientInfo patientInfo){
		return getHibernateTemplate().get(PatientInfo.class, patientInfo.getPid());
	}
	
	/* (non-Javadoc)
	 * @see s47.dqj.dao.PatientInfoDaoInf#findObjectByNamePhone(s47.dqj.bean.PatientInfo)
	 */
	@Override
	public PatientInfo findObjectByNamePhone(PatientInfo patientInfo){
		String hql="from PatientInfo as p where p.pname=:pname and p.pphone=:pphone";
		Query query=getSession().createQuery(hql);
		query.setString("pname", patientInfo.getPname());
		query.setString("pphone", patientInfo.getPphone());
		return (PatientInfo)query.uniqueResult();	
	}
	
	/* (non-Javadoc)
	 * @see s47.dqj.dao.PatientInfoDaoInf#save(s47.dqj.bean.PatientInfo)
	 */
	@Override
	public void save(PatientInfo patientInfo){
		getHibernateTemplate().save(patientInfo);
	}
	
	/* (non-Javadoc)
	 * @see s47.dqj.dao.PatientInfoDaoInf#update(s47.dqj.bean.PatientInfo)
	 */
	@Override
	public void update(PatientInfo patientInfo){
		getHibernateTemplate().update(patientInfo);
	}
}
